import axios from "axios";
import dayjs from "dayjs";

const load = (
  begTimeObj = new Date(),
  endTimeObj = new Date(),
  coverTime = true
) => {
  let begTime = coverTime
    ? dayjs(begTimeObj).format("YYYY-MM-DD") + " 00:00:00"
    : dayjs(begTimeObj).format("YYYY-MM-DD HH:mm:ss");
  let endTime = coverTime
    ? dayjs(endTimeObj).format("YYYY-MM-DD") + " 23:59:59"
    : dayjs(endTimeObj).format("YYYY-MM-DD HH:mm:ss");
  let uri = `api/flight_diversion_get.php?begTime=${begTime}&endTime=${endTime} `;
  return new Promise((resolve, reject) => {
    axios.get(uri).then((response) => {
      resolve(response.data);
    });
  });
};

export default { load };
